import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

const store = new Vuex.Store({
	state: {
		isLogin: false,
		userinfo: {},
		newFolder: [], // 最新收藏夹
		allFolder: [], // 全部收藏夹
	},
	mutations: {
		login(state, res) {
			state.isLogin = true;
			state.userinfo = res;
			uni.setStorageSync('userinfo', res);
		},
		logout(state, res) {
			state.isLogin = false;
			state.userinfo = {};
		},
		getNewFolder(state, data) {
			state.newFolder = data;
		},
		getAllFolder(state, data) {
			state.allFolder = data;
		},
		addFolder(state, data) {
			state.allFolder.push(data);
		},
		saveUserInfo(state, data) {
			state.userinfo.avatar = data.avatar;
			state.userinfo.nick_name = data.nick_name;
			state.userinfo.user_info.profile = data.profile;
			uni.setStorageSync('userinfo', state.userinfo);
		}
	}
})
export default store
